/*
 * Teste.java
 *
 * Created on __DATE__, __TIME__
 */

package telas.sistema;

import javax.swing.JFrame;
import javax.swing.UIManager;

import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
import com.jgoodies.looks.plastic.PlasticLookAndFeel;
import com.jgoodies.looks.plastic.theme.ExperienceBlue;
import telas.aluguel.TelaAluguel;
import telas.aluguel.TelaCliente;
import telas.aluguel.TelaProduto;
import telas.aluguel.TelaVeiculo;
import telas.comum.TelaChave;
import business.seguranca.Sistema;
import business.sistema.ExceptionSistema;

/**
 * 
 * @author __USER__
 */
public class TelaSistema extends javax.swing.JFrame
{
	{
		//Set Look & Feel
		try
		{
			//			javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
			//			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");

			PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());
			UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
		} catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	private static final long serialVersionUID = -2489425387427610878L;

	/** Creates new form Teste */
	public TelaSistema()
	{
		initComponents();
		setExtendedState(JFrame.MAXIMIZED_BOTH);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents()
	{

		desktopPane = new javax.swing.JDesktopPane();
		menuBar = new javax.swing.JMenuBar();
		mnArquivo = new javax.swing.JMenu();
		mniPropriedades = new javax.swing.JMenuItem();
		mniLicenca = new javax.swing.JMenuItem();
		mniSair = new javax.swing.JMenuItem();
		mnCadastros = new javax.swing.JMenu();
		mniVeiculoCadastro = new javax.swing.JMenuItem();
		jMenuItem1 = new javax.swing.JMenuItem();
		mnContratos = new javax.swing.JMenu();
		mniVeiculoContrato = new javax.swing.JMenuItem();
		jMenuItem3 = new javax.swing.JMenuItem();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("SysRent - Uni\u00e3o Ve\u00edculos");
		setExtendedState(6);

		mnArquivo.setText("Arquivo");

		mniPropriedades.setText("Propriedades");
		mnArquivo.add(mniPropriedades);

		mniLicenca.setText("Licen\u00e7a");
		mniLicenca.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				mniLicencaActionPerformed(evt);
			}
		});
		mnArquivo.add(mniLicenca);

		mniSair.setText("Sair");
		mniSair.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				mniSairActionPerformed(evt);
			}
		});
		mnArquivo.add(mniSair);

		menuBar.add(mnArquivo);

		mnCadastros.setText("Cadastros");

		mniVeiculoCadastro.setText("Ve\u00edculo");
		mniVeiculoCadastro
				.addActionListener(new java.awt.event.ActionListener()
				{
					public void actionPerformed(java.awt.event.ActionEvent evt)
					{
						mniVeiculoCadastroActionPerformed(evt);
					}
				});
		mnCadastros.add(mniVeiculoCadastro);

		jMenuItem1.setText("Clientes");
		jMenuItem1.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				jMenuItem1ActionPerformed(evt);
			}
		});
		mnCadastros.add(jMenuItem1);

		menuBar.add(mnCadastros);

		mnContratos.setText("Contratos");

		mniVeiculoContrato.setText("Aluguel de Ve\u00edculo");
		mniVeiculoContrato
				.addActionListener(new java.awt.event.ActionListener()
				{
					public void actionPerformed(java.awt.event.ActionEvent evt)
					{
						mniVeiculoContratoActionPerformed(evt);
					}
				});
		mnContratos.add(mniVeiculoContrato);

		jMenuItem3.setText("Produto");
		jMenuItem3.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent evt)
			{
				jMenuItem3ActionPerformed(evt);
			}
		});
		mnContratos.add(jMenuItem3);

		menuBar.add(mnContratos);

		setJMenuBar(menuBar);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 743,
				Short.MAX_VALUE));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addComponent(
				desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 436,
				Short.MAX_VALUE));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void mniLicencaActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			new TelaChave(this, true);
		}
		catch(Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			desktopPane.add(new TelaProduto());
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void mniVeiculoContratoActionPerformed(
			java.awt.event.ActionEvent evt)
	{
		try
		{
			desktopPane.add(new TelaAluguel());
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
	{
		try
		{
			desktopPane.add(new TelaCliente());
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void mniVeiculoCadastroActionPerformed(
			java.awt.event.ActionEvent evt)
	{
		try
		{
			desktopPane.add(new TelaVeiculo());
		} catch (Exception ex)
		{
			new ExceptionSistema(ex);
		}
	}

	private void mniSairActionPerformed(java.awt.event.ActionEvent evt)
	{
		System.exit(0);
	}

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[])
	{
		java.awt.EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					Sistema sistema = (Sistema) new Sistema().obterObjeto(0);

					if (sistema != null && !sistema.isExpirado())
					{
						TelaSistema telaSistema = new TelaSistema();

						telaSistema.setVisible(true);
					} else
					{
						new TelaChave(null, true);

						sistema = (Sistema) new Sistema().obterObjeto(1);

						if (sistema != null && !sistema.isExpirado())
						{
							TelaSistema telaSistema = new TelaSistema();

							telaSistema.setVisible(true);
						}
					}
				} catch (Exception ex)
				{
					ex.printStackTrace();
				}
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JDesktopPane desktopPane;
	private javax.swing.JMenuItem jMenuItem1;
	private javax.swing.JMenuItem jMenuItem3;
	private javax.swing.JMenuBar menuBar;
	private javax.swing.JMenu mnArquivo;
	private javax.swing.JMenu mnCadastros;
	private javax.swing.JMenu mnContratos;
	private javax.swing.JMenuItem mniLicenca;
	private javax.swing.JMenuItem mniPropriedades;
	private javax.swing.JMenuItem mniSair;
	private javax.swing.JMenuItem mniVeiculoCadastro;
	private javax.swing.JMenuItem mniVeiculoContrato;
	// End of variables declaration//GEN-END:variables

}